package com.dyp.jdbcstarter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

@SpringBootApplication
public class JdbcStarterApplication implements CommandLineRunner {
	Logger logger = LoggerFactory.getLogger(JdbcStarterApplication.class);

	@Autowired
	DataSource dataSource;

	public static void main(String[] args) {
		SpringApplication.run(JdbcStarterApplication.class, args);
	}

	@Override
	public void run(String... args) throws Exception {
		System.out.println("服务启动执行:");
		logger.info("dataSource:{}", dataSource.getClass().getName());
		Connection connection = dataSource.getConnection();
		logger.info("connection:{}", connection.toString());
	}
}
